package com.example.mall.web.controller;

import com.example.mall.domain.PaymentMethods;
import com.example.mall.dto.PaymentMethodsDto;
import com.example.mall.exception.ErrorEnumCode;
import com.example.mall.exception.GlobalCustomerException;
import com.example.mall.query.PageDTO;
import com.example.mall.query.PaymentMethodsQuery;
import com.example.mall.result.JSONResult;
import com.example.mall.service.IPaymentMethodsService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/paymentMethods")
public class PaymentMethodsController {

    @Autowired
    public IPaymentMethodsService paymentMethodsService;

    /**
     * 分页查询支付方式表信息
     * @param paymentMethodsQuery
     * @return
     */
    @GetMapping("queryPage")
    @ApiOperation(value = "分页查询支付方式表信息",notes = "分页查询支付方式表信息",httpMethod = "GET")
    public JSONResult queryPage(PaymentMethodsQuery paymentMethodsQuery){
        PageDTO<PaymentMethodsDto> paymentMethodsDtoPageDTO = paymentMethodsService.queryPage(paymentMethodsQuery);
        return JSONResult.success("查询成功",paymentMethodsDtoPageDTO);
    }

    /**
     * 根据id查询支付方式表信息
     * @param methodId
     * @return
     */
    @GetMapping("query/{methodId}")
    @ApiOperation(value = "根据id查询支付方式表信息",notes = "根据id查询支付方式表信息",httpMethod = "GET")
    public JSONResult query(@PathVariable("methodId")Long methodId){
        //1.根据id查询用户信息
        if (methodId == null){
            throw new GlobalCustomerException(ErrorEnumCode.METHODID_NOT_ID);
        }
        PaymentMethods paymentMethods = paymentMethodsService.getById(methodId);
        return JSONResult.success("查询成功",paymentMethods);
    }

    /**
     * 根据id查询支付方式表信息
     * @param methodId
     * @return
     */
    @GetMapping("queryPaymentMethodsById/{methodId}")
    @ApiOperation(value = "根据id查询支付方式表信息",notes = "根据id查询支付方式表信息",httpMethod = "GET")
    public JSONResult queryPaymentMethodsById(@PathVariable("methodId")Long methodId){
        //1.根据id查询用户信息
        if (methodId == null){
            throw new GlobalCustomerException(ErrorEnumCode.METHODID_NOT_ID);
        }
        PaymentMethods paymentMethods = paymentMethodsService.queryPaymentMethodsById(methodId);
        return JSONResult.success("查询成功",paymentMethods);
    }

    /**
     * 查询全部支付方式表信息
     * @param
     * @return
     */
    @GetMapping("queryPaymentMethodsList")
    @ApiOperation(value = "查询全部支付方式表信息",notes = "查询全部支付方式表信息",httpMethod = "GET")
    public JSONResult queryPaymentMethodsList(){
        List<PaymentMethods> paymentMethods = paymentMethodsService.queryPaymentMethodsList();
        return JSONResult.success("查询成功",paymentMethods);
    }

    /**
     * 新增支付方式表
     * @param paymentMethodsDto
     * @return
     */
    @PostMapping("insert")
    @ApiOperation(value = "新增支付方式表",notes = "新增支付方式表",httpMethod = "POST")
    public JSONResult insert(@RequestBody PaymentMethodsDto paymentMethodsDto){
        paymentMethodsService.insert(paymentMethodsDto);
        return JSONResult.success("保存成功");
    }

    /**
     * 修改支付方式表信息
     * @param paymentMethodsDto
     * @return
     */
    @PostMapping("update")
    @ApiOperation(value = "修改支付方式表信息",notes = "修改支付方式表信息",httpMethod = "POST")
    public JSONResult update(@RequestBody PaymentMethodsDto paymentMethodsDto){
        paymentMethodsService.update(paymentMethodsDto);
        return JSONResult.success("修改成功");
    }

    /**
     * 删除支付方式表信息
     * @param methodId
     * @return
     */
    @PostMapping("delete/{methodId}")
    @ApiOperation(value = "删除支付方式表信息",notes = "删除支付方式表信息",httpMethod = "POST")
    public JSONResult delete(@PathVariable("methodId") Long methodId) {
        paymentMethodsService.delete(methodId);
        return JSONResult.success("删除成功");
    }

    /**
     * 批量删除支付方式表信息
     * @param methodIds
     * @return
     */
    @PostMapping("deleteBatch")
    @ApiOperation(value = "批量删除支付方式表信息",notes = "批量删除支付方式表信息",httpMethod = "POST")
    public JSONResult deleteAll(@RequestBody List<Long> methodIds) {
        paymentMethodsService.deleteBatch(methodIds);
        return JSONResult.success("批量删除成功");
    }
}
